<?php

class cLine
{
	protected $start;
	protected $end;

	protected $dx;
	protected $dy;
	protected $dz;
	
	protected $sizeX;
	protected $sizeY;
	protected $sizeZ;
	
	public function __construct(cPoint3 $start,cPoint3 $end)
	{
		$this->start = $start;
		$this->end = $end;
		
		$this->dx = $this->end->getX() - $this->start->getX();
		$this->dy = $this->end->getY() - $this->start->getY();
		$this->dz = $this->end->getZ() - $this->start->getZ();
		
		$this->sizeX = abs($this->dx);
		$this->sizeY = abs($this->dy);
		$this->sizeZ = abs($this->dz);
		
	}
	
	protected function percentage($pos,$min,$size)
	{
		return ($pos - $min) / $size;
	}
	
	protected function scale($percent,$min,$size)
	{
		return ($percent * $size) + $min;
	}
	
	public function getPointForX($x)
	{
		$percent = $this->percentage($x,$this->start->getX(),$this->dx);
		$y = $this->scale($percent,$this->start->getY(),$this->dy);
		$z = $this->scale($percent,$this->start->getZ(),$this->dz);
		return new cPoint3($x,$y,$z);
	}
	
	public function getPointForY($y)
	{
		$percent = $this->percentage($y,$this->start->getY(),$this->dy);
		$x = $this->scale($percent,$this->start->getX(),$this->dx);
		$z = $this->scale($percent,$this->start->getZ(),$this->dz);
		return new cPoint3($x,$y,$z);		
	}
	
	public function getPointForZ($z)
	{
		$percent = $this->percentage($z,$this->start->getZ(),$this->dz);
		$x = $this->scale($percent,$this->start->getX(),$this->dx);
		$y = $this->scale($percent,$this->start->getY(),$this->dy);
		return new cPoint3($x,$y,$z);			
	}

	public function dX()
	{
		return $this->dx;
	}
	
	public function dY()
	{
		return $this->dy;
	}

	public function dZ()
	{
		return $this->dz;
	}
	
	public function sX()
	{
		return $this->sizeX;	
	}

	public function sY()
	{
		return $this->sizeY;	
	}
	
	public function sZ()
	{
		return $this->sizeZ;	
	}	

	public function minX()
	{
		return min($this->start->getX(),$this->end->getX());
	}

	public function minY()
	{
		return min($this->start->getY(),$this->end->getY());
	}

	public function minZ()
	{
		return min($this->start->getZ(),$this->end->getZ());
	}	
	
	public function maxX()
	{
		return max($this->start->getX(),$this->end->getX());
	}
	
	public function maxY()
	{
		return max($this->start->getY(),$this->end->getY());
	}

	public function maxZ()
	{
		return max($this->start->getZ(),$this->end->getZ());
	}	
}

?>